<?php
namespace app\index\controller;
use app\index\model\Partner;

class Companylogin extends Common
{
    public function _initialize()
    {
        parent::_initialize();
        if (!in_array(ACTION_NAME, ['logout'])) {
            if (CheckComLogin()) {
                $this->redirect('Company/index');
            }
        }

    }

    public function index()
    {
        return $this->fetch();
    }

    /**
     * 用户登录
     */
    public function loginin(){
        if(request()->isAjax()){
            $data = input('post.');
            $Partner = new Partner;
            if(!captcha_check($data['code'])){
                return ajaxReturn('图形验证码不正确');
            }
            $mobile = base64_decode($data['lockm']);
            $password = md5(base64_decode($data['lockcode']));
            $member = $Partner->where(['mobile'=>$mobile])->find();
            if(empty($member)){
                return ajaxReturn('用户不存在');
            }
            if($password!=$member['password']){
                return ajaxReturn('密码错误');
            }else{
                session('CID',$member['id']);
                session('CName',$member['username']);
                session('Cmobile',$member['mobile']);
                session('isCheck',$member['is_check']);
                return ajaxReturn('登录成功',url('Company/index'));
            }
        }
    }
    public function logout(){
        session('CID',null);
        session('CName',null);
        session('Cmobile',null);
        session('isCheck',null);
        return redirect('Index/index');
    }
}